<template>
	<view class="pages">
		<u-subsection :list="list" mode="subsection" :current="index" @change="sectionChange"></u-subsection>
		<view class="list_box">
			<template v-if="shopList.length != 0">
				<view class="availabilityList" v-for="(itemshop,indexshop) in shopList" :key="indexshop">
					<view class="shopList">
						<u--image :src="itemshop.mediaUrl || '../../../static/default/default.png'" width="100px"
							height="100px" radius="5" @click="detail(itemshop)"></u--image>
						<view class="description">
							<view class="title">
								<view class="description_title">
									{{itemshop.communityName}}
								</view>
								<view class="titleType error" v-if="index == 0">
									未支付
								</view>
								<view class="titleType success" v-if="index == 1">
									已支付
								</view>
							</view>
							<view class="description_squaremetre">
								{{ itemshop.houseRoomName}}
							</view>
							<view class="button_row" @click="detail(itemshop)">
								<view v-for="(tagItem, tagIndex) of changeList(itemshop.labels)" :key="tagIndex"
									style="margin: 5rpx;">
									<u-tag type="info" shape="circle" plain size="mini" :text="tagItem"
										borderColor="#c7c7c7"></u-tag>
								</view>
								<!-- <view class="button_1" v-for="(tagItem, tagIndex) of changeList(itemshop.labels)"
									:key="tagIndex" :style="{backgroundColor: labelsColor[tagIndex]}">
									{{tagItem}}
								</view> -->
							</view>
							<view class="row">
								<view class="money">
									{{itemshop.serviceCharge}}
									<view class="unit">
										元/月
									</view>
								</view>
								<view class="buttonRow" v-if="index == 0">
									<u-button type="primary" size="small" text="去支付"
										@click="confirmLease(itemshop)"></u-button>
								</view>
							</view>
						</view>
					</view>

				</view>
			</template>
		</view>
		<view v-if="shopList.length == 0">
			<u-empty icon="https://cdn.uviewui.com/uview/empty/data.png">
			</u-empty>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import {
		serviceOrderList,
	} from "@/api/home/index.js"

	export default {
		data() {
			return {
				pageSize: 10,
				index: 0,
				list: ['未付款', '已付款'],
				labelsColor: ['#f56c6c', '#f9ae3d', '#5ac725', '#3c9cff', '#e3e3e3'],
				shopList: [],
				payType: null,
			}
		},
		onLoad() {
			this.getList();
			// 获取provider
			// uni.getProvider({
			// 	service: "payment",
			// 	success: (e) => {
			// 		e.provider.map((value) => {
			// 			switch (value) {
			// 				case 'wxpay':
			// 					this.setData({
			// 						payType: 'wxpay'
			// 					})
			// 					break;
			// 				default:
			// 					break;
			// 			}
			// 		})
			// 	},
			// 	fail: (e) => {
			// 		console.log(e)
			// 		return false;
			// 	}
			// });
		},
		methods: {
			//去支付
			confirmLease(itemshop) {
				uni.navigateTo({
					url: './toPay?itemshop=' + JSON.stringify(itemshop),
					animationType: this.animation.type,
					animationDuration: this.animation.time
				})
			},
			changeList(str) {
				var labels = ""
				if (str) {
					labels = str.split(',')
				} else {
					labels = []
				}
				return labels
			},

			async getList() {
				const res = await serviceOrderList(this.index)
				if (res.data.code != 200) return this.$refs.uToast.show({
					message: res.data.msg,
					type: 'error'
				})
				this.shopList = res.data.rows

			},
			sectionChange(index) {
				this.index = index;
				this.getList();
			},
			detail(itemshop) {
				uni.navigateTo({
					url: './orderDetail?id=' + itemshop.id,
					animationType: this.animation.type,
					animationDuration: this.animation.time
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import "~@/styles/index.scss";
	@import "~@/styles/global.scss";

	.list_box {
		padding: 0 30rpx;
		box-sizing: border-box;
	}

	.pages {
		width: 100%;
		max-height: 100%;
		min-height: 100vh;

		// background-color: $pagebgc;
		.availabilityList {
			width: 100%;
			box-sizing: border-box;
			padding: 20rpx;
			@include boxshadow;
			margin-top: 30rpx;
			border-radius: 20rpx;

			.tiem {
				// text-align: center;
				color: #7f7f7f;
				font-size: 24rpx;
				padding: 20rpx 0;
			}

			.shopList {
				border-radius: 10rpx;
				display: flex;
				// padding: 20rpx;
				margin-bottom: 20rpx;
				background-color: white;

				.description {
					width: 100%;
					margin-left: 20rpx;

					.title {
						display: flex;
						justify-content: space-between;
						align-items: center;

						.description_title {
							font-weight: bold;
							font-size: 36rpx;
						}

						.titleType {
							font-weight: bold;
							font-size: 32rpx;
						}

						.success {
							color: #7f7f7f;
						}

						.error {
							color: #d02d37;
						}

						.primary {
							color: #79b8f4;
						}
					}

					.description_squaremetre {
						color: #7f7f7f;
						font-size: 28rpx;
						padding: 10rpx 0;
					}
				}

				.buttonRow {
					display: flex;
					justify-content: flex-end;
				}

				.buttonRow_ {
					width: 30%;
					margin-left: auto;
				}

				.button_row {
					display: flex;
					justify-content: flex-start;
					flex-wrap: wrap;
					overflow: hidden;
					margin-top: 20rpx;
				}

				.row {
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin: 5rpx 0;

					.money {
						font-weight: bold;
						font-size: 42rpx;
						color: red;
						display: flex;
						align-items: center;

						.unit {
							font-size: 28rpx;
						}
					}

					.buttom {
						display: flex;
						align-items: center;

						.custom-style {
							margin-left: 10rpx;
						}
					}

				}

			}
		}
	}
</style>